﻿<!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>
body { background-color: #EEFFEE;  font-size: 1.0rem; font-family: Arial; max-width: 60rem;
      color: #000000; margin: 0px;
      padding-left:  0px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
H1 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom: 10px; font-size: 1.4rem; }
H2 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom:  0px; font-size: 1.2rem; }
blockquote {
  tab-size: 3rem;
  color: #88FF88; background: #000000;
  font-size: 0.95rem; font-family: monospace;
  padding-left: 5px; padding-right: 5px;
  padding-top: 5px; padding-bottom: 5px;
}
P {   padding-left: 20px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
IMG { padding-left:  0px; padding-right:  0px; padding-top:  2px; padding-bottom:  0px;
      max-width: 100%; }
A { display: inline; border-radius: 4px;
    font-size: 1.0rem; font-family: Arial; color: #000044; text-decoration: none;
    padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; }
A:hover { color: #FFFF00; background: #000044; }
A:active { color: #FFFFFF; background: #444444; }
</STYLE> </HEAD> <BODY>
<IMG SRC="Images/Title.png" ALT="Images/Title.png">
<P>
<A href="Manual.html">Back to main page</A>
</P><P>
</P><H1> Buffers</H1><P>Every file that is saved or loaded in the framework will pass through a Buffer.
Buffers can not refer to each other in cycles and are automatically reference counted and deleted, so that you don't have to worry about memory leaks from them unless you explicitly call buffer_replaceDestructor.
They store a fixed size allocation of 128-bit padded and aligned memory to work well with 128-bit SIMD intrinsics.

</P><P>
</P><IMG SRC="Images/Border.png"><P>
</P><H2> Construction</H2><P>
</P><P>
The default constructor creates an empty handle, so dsr::Buffer() can be treated as null and checked using the buffer_exists function.
Returning an empty buffer handle is common when something went wrong with an operation.

</P><P>
To create a buffer that actually stores something, call buffer_create with the number of bytes to contain as the only argument.
The memory always start initialized to zero, which prevents random bugs.

</P><P>
If you create a buffer of size zero, it will allocate the head but not the data.
Trying to clone an empty buffer head will just return the same handle without cloning, because empty buffers are immutable.
</P><IMG SRC="Images/Border.png"><P>
</P><H2> Read and write data access</H2><P>
</P><P>
Trying to get the pointer of a non-existing or zero length Buffer will safely return a null pointer, no matter if you use buffer_getSafeData<type>(buffer, "Buffer name") or buffer_dangerous_getUnsafeData(buffer).
You access the data by getting a SafePointer, which can later be sliced into smaller parts.
Sometimes you can't use the SafePointer because an operating system wants a regular C pointer.
</P><IMG SRC="Images/Border.png"><P>
</P>
</BODY> </HTML>
